import es, wcs, random
from wcs import wcs
#Register Item syntax: registerItem(name, section, cost, fire, function)
#Different Sections for menus: enhancement, powerup, attack, defense, special
'''
Acceptable Fire Commands:
onbuy = Runs when the item is bought
onetime = Makes the item only run once, does not effect the user's maxitem count and only triggers the onbuy fire
spawn = Runs when a player spawns
pickup = runs when the user picks up an item
userhurt = runs when the user hits/gets hit
attackerhurt = runs when a user hits someone
userdeath = runs when the user dies and when they kill someone
attackerdeath = runs when you kill someone
'''
def load():
	wcs.ShopMenu().registerItem('Cloak of Shadows','enhancement',2000,('onbuy','pickup'),CloakLevel1)
	wcs.ShopMenu().registerItem('Boots of Speed','enhancement',3500,('onbuy','spawn'),BootsofSpeed)
	wcs.ShopMenu().registerItem('Claws of Attack','attack',2500,('onbuy','attackerhurt','userdeath'),ClawsofAttack)
	wcs.ShopMenu().registerItem('Orb of Frost','attack',3000,('attackerhurt'),OrbofFrost)
	wcs.ShopMenu().registerItem('Ring of Regeneration','defense',4000,('onbuy','spawn'),RingofRegeneration)
	wcs.ShopMenu().registerItem('Goggles of the Sun','defense',2000,('flash'),GogglesoftheSun)
	wcs.ShopMenu().registerItem('Potion of Healing','special',800,('onbuy','onetime'),PotionofHealing)
	wcs.ShopMenu().registerItem('Tome of Xp','special',5000,('onbuy','onetime'),TombofXp)
	wcs.ShopMenu().registerItem('Periapt of Health','powerup',6000,('onbuy','onetime'),PeriaptofHealth)
	wcs.ShopMenu().registerItem('Tome of Health','powerup',4500,('onbuy','spawn'),TomeofHealth)
'''
Values Passes into Item Methods based on type:
spawn, onbuy, and pickup:
userid
userteam
hurt and death:
userid
userteam
attacker
attackerteam
(Hurt also passes the damage dealt in: damage)
'''
def GogglesoftheSun(values):
	playerUser = playerlib.getPlayer(event_var['userid'])
	playerUser.set('flash',[playerUser.get('flashalpha')/2,playerUser.get('flashduration')/2])
def RingofRegeneration(values):
	wcs.Command(values['userid']).Regen(1,1)
def OrbofFrost(values):
	if not random.randrange(19):
		wcs.Command(values['userid']).Freeze(4)
def TombofXp(values):
	wcs.Command(values['userid']).GiveXp(100)
def TomeofHealth(values):
	wcs.Command(values['userid']).HealthAdd(50)
def PeriaptofHealth(values):
	wcs.Command(values['userid']).HealthAdd(100)
def PotionofHealing(values):
	wcs.Command(values['userid']).Heal(random.randint(12,27))
def CloakLevel1(values):
	wcs.Command(values['userid']).Color(alpha=255*.6)
def BootsofSpeed(values):
	wcs.Command(values['userid']).SpeedAdd(.1)
def ClawsofAttack(values):
	if values['type'] == 'onbuy':
		userKey = wcs.Command(values['userid']).ReturnUserKey()
		if userKey.has_key('damage percent bonus'):
			userKey['damage percent bonus'] += .6
		else:
			userKey['damage percent bonus'] = .6
	elif values['type'] == 'hurt':
		wcs.Command(values['userid']).Damage(values['damage']*wcs.Command(values['attacker']).ReturnDict('damage percent bonus'),32,values['attacker'])
	elif values['type'] == 'userdeath':
		wcs.Command(values['userid']).UpdateDict('damage percent bonus',0.0)